<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增员工假期')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-holiday-add">

            <div class="form-group">
                <label class="col-sm-3 control-label labelReqerd is-required">员工：</label>
                <div class="col-sm-8">
                    <!--<input class="form-control" type="text" name="leader">-->
                    <div class='input-group'>
                        <input class='form-control' type='hidden' name='empId' id='empId' required>
                        <input class='form-control' type='hidden' name='userId' id='userId' required>
                        <input class='form-control' type='text' name='empName' id='empName' readonly="readonly" required>
                        <span class='input-group-addon input-sm' onclick='selectEmpTree("", this)'>
                            <i class='fa fa-search'>选择</i>
                        </span>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">假期类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="form-control m-b" th:with="type=${@dict.getType('biz_leave_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">假期时长(单位小时)：</label>
                <div class="col-sm-8">
                    <input name="hours" class="form-control" type="text" onkeyup="value=value.replace(/[^\d.]/g,'')" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">已用假期时长(单位小时)：</label>
                <div class="col-sm-8">
                    <input name="useHours" class="form-control" type="text" onkeyup="value=value.replace(/[^\d.]/g,'')">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">开始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="startDate" class="form-control" readonly="readonly" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="endDate" class="form-control" readonly="readonly" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">来源：</label>
                <div class="col-sm-8">
                    <input name="source" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "hr/holiday"

        // 选择字典处理函数
        function selectEmpTree(columnId, obj) {
            // var dictType = $.common.nullToStr($(obj).parent().find("input").val());
            var url = ctx + "system/user/selectUserTree";
            var options = {
                title: '选择员工',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            // debugger
            var body = layer.getChildFrame('body', index);
            var userId = body.find('#userId').val();
            var empName = body.find('#empName').val();
            var userNameShow = body.find('#userNameShow').val();
            layer.close(index);
            $("#empId").val(userId);
            $("#userId").val(userId);
            $("#empName").val(empName);
            // $("#auditName").val(loginName);
            // document.getElementById("userName").value=userName;
        }

        $("#form-holiday-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form() && validateStartTimeAndEndTime()) {
                $("select[name=deptId]").attr("disabled",false);
                $("select[name=postId]").attr("disabled",false);
                $.operate.save(prefix + "/add", $('#form-holiday-add').serialize());
            }
        }

        $("input[name='startDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function validateStartTimeAndEndTime() {
            if ($('input[name="startDate"]').val() > $('input[name="endDate"]').val()) {
                $.modal.alertWarning("结束时间必须大于开始时间");
                return false;
            }
            return true;
        }
    </script>
</body>
</html>